<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String title = "信息综合系统";
%>
<%@ include file="/WEB-INF/jsp/header.jsp"%>
<title><%=title%>-季度任务管理</title>

<meta name="viewport"
	content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-itunes-app" content="app-id=429849944" />
<meta name="apple-touch-fullscreen" content="no" />
<meta content="telephone=no" name="format-detection" />
<meta name="apple-mobile-web-app-capable" content="no" />
</head>

<!-- 根据不同的终端显示不同的页面
<script type="text/javascript">
    function urlredirect() {
        var sUserAgent = navigator.userAgent.toLowerCase(); 
        if ((sUserAgent.match(/(ipod|iphone os|midp|ucweb|android|windows ce|windows mobile)/i))) {
            var thisUrl = window.location.href;
            window.location.href = thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'mobpage/'; //跳转为网址后面加mobile的路径
        }
    }
urlredirect();
</script>
-->

<body class="fixed-top" style="background: #fff;" onload="loadQueryDIV()">
	<div class="container-fluid">
		<!-- BEGIN PAGE HEADER 头部-->
		<div class="row-fluid">
			<div class="span12">
				<ul class="breadcrumb"
					style="padding-bottom: 12px; background: #fff;">
					<li><a href="${pageContext.request.contextPath}/user/index.do">
							<i class="icon-angle-left"></i> <i class="icon-angle-left"></i>
							&nbsp;&nbsp; 首页控制台
					</a> <span class="divider">/</span></li>
					<li class="active">季度任务管理</li>
					<li class="pull-right search-wrap">
						<!-- <button onclick="toggleCondi_sample();"
							class="btn dropdown-toggle" data-toggle="dropdown">
							<span id="but_text_sample">显示筛选</span> <i id="toggleCondi_i"
								class="icon-angle-down"></i>
						</button> &nbsp;  -->
						<input type="button" id="seach" name="seach" value="查询"
						class="btn  btn-primary" style="margin-bottom: 10px;"
						onclick="query(pNumber,pSize);" /> 
						
						<input type="reset" id="reset"
						name="reset" value="刷新" class="btn  btn-primary"
						style="margin-bottom: 10px;" onclick="resetf();" /> &nbsp;


						<div class="btn-group pull-right">
							<button class="btn dropdown-toggle" data-toggle="dropdown">
								更多 <i class="icon-angle-down"></i>
							</button>
							<ul class="dropdown-menu pull-right">
								<%-- <c:if test="${user.lev>=1}"> --%>
									<li><a
										href="${pageContext.request.contextPath}/task/downloadTotal.do">下载季度任务总表</a></li>
									<li><a
										href="${pageContext.request.contextPath}/task/download.do">下载已筛选的季度任务</a></li>
									<li><a href="#" onclick="openUpload('季度任务');">Excel批量上传N条</a></li>
									<li><a href="${pageContext.request.contextPath}/task/total_ui.do" target="_blank">查询季度任务总表</a></li>
								<%-- </c:if> --%>
									<li>
									<a href="javascript:;" id="newadd"
										onclick="addRow();" title="新增一行">页面新增一条</a>
									
									</li>
							</ul>
						</div>
					</li>
				</ul>
			</div>
		</div>
		
		<!-- 查询条件 -->
		<div class="row-fluid">
            <div class="span12" id="query_canvas-wrap">
               <div class="widget gray">
                   <div class="widget-title">
                       <h4><i class="icon-reorder"></i>
                     	  查询条件
                       </h4>
                       <span class="tools">
							<a href="javascript:;" onclick="up_down_active()" id="query_id" class="icon-chevron-down"></a>
					   </span>
                   </div>
                   <div class="widget-body" id="query_div" style="background: #FCFCFC;display:none;">
	                   <div class="clearfix" style="display:;">
	               		<form method="post" id="filterForm">
	               		
	                   <select id="province" size="1" name="province" multiple="multiple"
	                   		class="input-medium m-wrap">
	                       <c:forEach items="${provinces}" var="shenfen" >
	                           <option value="${shenfen}">${shenfen}</option>
	                       </c:forEach>
	                   </select>
	
	                   <select id="city" size="1" name="city" multiple="multiple"
	                   	   class="input-medium m-wrap">
	                       <option value="">地市</option>
	                       <c:forEach items="${citys}" var="city">
	                           <option value="${city}">${city}</option>
	                       </c:forEach>
	                   </select>
	
	                   <select id="county" size="1" name="country" multiple="multiple"
	                   		class="input-medium m-wrap">
	                       <c:forEach items="${countrys}" var="country" varStatus="status">
	                           <option value="${country}">${country}</option>
	                       </c:forEach>
	                   </select>
	                   
	                   <select id="clientLevel" size="1" name="clientLevel" multiple="multiple"
	                        class="input-medium m-wrap" onMouseOver="this.title='客户级别'">
	                       <c:forEach items="${clientLevels}" var="clientLevel" >
	                           <option value="${clientLevel}">${clientLevel}</option>
	                       </c:forEach>
	                   </select>
	                   
	                   <select id="product" name="product" multiple="multiple"
							onMouseOver="this.title='选择品种'" size="1"
							class="input-medium m-wrap">
							<c:forEach items="${products}" var="product" >
	                           <option value="${product}">${product}</option>
	                       </c:forEach>
						</select> 
						
	                   <select id="page" size="1" name="page" multiple="multiple"
	                        class="input-medium m-wrap">
	                       <c:forEach items="${packs}" var="page">
	                           <option value="${page}">${page}</option>
	                       </c:forEach>
	                   </select>
	                   <select id="isTerminal" size="1" name="isTerminal" multiple="multiple"
	                        class="input-medium m-wrap">
	                       <option value="1">1</option>
	                       <option value="0">0</option>
	                   </select>
	                   <select id="isCountry" size="1" name="isCountry" multiple="multiple"
	                        class="input-medium m-wrap">
	                       <option value="1">1</option>
	                       <option value="0">0</option>
	                   </select>
	                   <select id="eventRef" size="1" name="eventRef" multiple="multiple"
	                        class="input-medium m-wrap">
	                       <option value="1">1</option>
	                       <option value="0">0</option>
	                   </select>
	                   <input type="text" class="typeahead" style="width:120px;" id="client" name="client"
	                        ondblclick="clearText('client')"
	                        onMouseOver="this.title='客户'"
	                        placeholder="客户" data-provide="typeahead" data-items="4"/>
	                        
	                   <input type="text" class="typeahead" style="width:120px;" id="terminalQs" name="terminalQs"
	                        onMouseOver="this.title='终端QS名"
	                        ondblclick="clearText('event')"
	                        placeholder="终端QS名" data-provide="typeahead" data-items="4" />
	                   <input type="text" style="width:130px;" id="event" name="event"
	                        placeholder="活动安排" value=""/>
	                   
	                   <input type="text" style="width:135px;" id="note" name="note"
	                        placeholder="备注" value=""/>
	        		 </form>
	               </div>
                   
                   </div>
              	 </div>
           	</div>
       	</div>
       		
		
		<!-- 弹框 -->
		<div class="widget">
			<div class="purple">
				<!-- 通过id删除 -->
				<div id="deleteDiv" hidden>
					<div class="modal-body">
						请输入要删除的ID:<input type="text" class="span5" name="idD"
							style="padding: 13px 5px;" id="idD" value=""
							placeholder="多个ID用空格隔开" />
					</div>
				</div>

				<!-- 错误提示 -->
				<div id="errorInfoDiv" hidden="hidden">
					<table class="table table-striped table-hover table-bordered"
						style="font-size: 11px; color: red; width: 750px; margin: 12px;">
						<thead>
							<tr>
								<td><b>出错行号</b></td>
								<td><b>出错标题</b></td>
								<td style="color: #479DA4;"><b>参考标准提示</b></td>
								<td><b>错误字段</b></td>
							</tr>
						</thead>
						<tbody id="error-body"></tbody>
					</table>
				</div>

				<!-- 新增、更新 表单 -->
				<div id="form_div" hidden>
					<div class="modal-body" style="height: 90%">
						<form method="post" id="submitForm">
							<input id="idU" name="id" hidden="hidden" /> <span
								style="color: red;">*</span>&nbsp;请填写经理: <input type="text"
								class="span2 typeahead noNull" name="mgr" style="width: 100px;"
								id="mgrU" placeholder="请填写经理" data-provide="typeahead"
								data-items="4" /> <span style="color: red;">*</span>&nbsp;
							<p style="display: inline">请选择大区：</p>
							<select id="daquU" class="input-medium m-wrap noNull" name="daqu">
								<option value=""></option>
								<c:forEach items="${condiMap.province}" var="province"
									varStatus="status">
									<option value="${province}">${province}</option>
								</c:forEach>
							</select> <span style="color: red;">*</span>&nbsp;
							<p style="display: inline">请选择片区：</p>
							<select id="spaceU" size="1" class="input-medium m-wrap noNull"
								name="space">
								<option value=""></option>
								<c:forEach items="${condiMap.space}" var="space"
									varStatus="status">
									<option value="${space}">${space}</option>
								</c:forEach>
							</select> </br> <span style="color: red;">*</span>&nbsp;
							<p style="display: inline">请选择省份：</p>
							<select id="provinceU" size="1"
								class="input-medium m-wrap noNull" name="province">
								<option value=""></option>
								<c:forEach items="${condiMap.shengfen}" var="shenfen"
									varStatus="status">
									<option value="${shenfen}">${shenfen}</option>
								</c:forEach>
							</select> <span style="color: red;">*</span>&nbsp;
							<p style="display: inline">请选择地市：</p>
							<input type="text" class="span2 typeahead noNull" name="city"
								style="width: 100px;" id="cityU" placeholder="请填写地市"
								data-provide="typeahead" data-items="4" /> <span
								style="color: red;">*</span>&nbsp;
							<p style="display: inline">请选择区县：</p>
							<input type="text" class="span2 typeahead noNull" name="country"
								style="width: 100px;" id="countyU" placeholder="请填写区县"
								data-provide="typeahead" data-items="4" /> </br>
							<p style="display: inline">请选择分组标识：</p>
							<select id="productU" size="1" name="product"
								class="input-medium m-wrap">
								<option value=""></option>
								<option value="Rx">Rx</option>
								<option value="OTC">OTC</option>
								<option value="A">A</option>
								<option value="Y">Y</option>
								<option value="Z">Z</option>
								<option value="T1">T1</option>
								<option value="T2">T2</option>
								<option value="T3">T3</option>
								<option value="T4">T4</option>
							</select>
						</form>
					</div>
				</div>

				<!-- 文件上传 -->
				<div id="uploadFileForm" hidden>
					<div class="modal-body">
						<form action="${pageContext.request.contextPath}/task/upload.do"
							method="post" id="uploadForm" enctype="multipart/form-data">
							点击该按钮选择文件:<input type="file" name="excelFile" multiple="multiple"
								class="input-medium" id="file"><br />
						</form>
					</div>
				</div>

				<!-- list查询列表 -->
				<div class="row-fluid">
					<div class="span12">
						<!-- BEGIN ALERTS PORTLET-->
						<div class="widget blue">
							<div class="widget-title">
								<h4>
									<i class="icon-reorder"></i> <a href="javascript:;"
										onclick="scrollToLeft();" title="定位到表格最左端"
										style="color: white;">最左</a> <a href="javascript:;"
										onclick="scrollToCenter();" title="定位到表格正中间"
										style="color: white;">居中</a> <a href="javascript:;"
										onclick="scrollToRight();" title="定位到表格最右端"
										style="color: white;">最右</a> 
								</h4>
								<span class="tools"> <a href="javascript:;"
									class="icon-chevron-down"></a>
								</span>
							</div>
							<div class="widget-body" style="overflow: auto" id="canvas-wrap">
								<form id="newTask"
									action="${pageContext.request.contextPath }/task/save.do" method="post">
									<table class="table table-striped table-hover table-bordered"
										width="2788px;" style="table-layout: fixed">
										<thead id="distribute-thead">
											<tr>
												<!--  <th style="width:15px;">
                            					<input type="checkbox" name="choiceAll" value="all" id ="allAndNotAll"/></th> -->
												<th width="40px">省份</th>
												<th width="40px">地市</th>
												<th width="40px">区县</th>
												<th width="40px">经理</th>
												<th width="40px">客户</th>
												<th width="30px">客户级别</th>
												<th width="30px">产品</th>
												<th width="30px">包装</th>
												<th width="80px">终端QS名</th>
												<th width="30px">终端类型</th>
												<th width="50px">终端级别</th>
												<th width="50px">重点终端</th>
												<th width="50px">重点区县</th>
												<th width="40px">协议测算价</th>
												<th width="40px">Y18M10纯销</th>
												<th width="40px">Y18M11纯销</th>
												<th width="40px">Y18M12纯销</th>
												<th width="50px">Y19M1纯销目标</th>
												<th width="50px">Y19M2纯销目标</th>
												<th width="50px">Y19M3纯销目标</th>
												<th width="40px">目标增长率</th>
												<th width="220px">活动安排</th>
												<th width="50px">活动费用</th>
												<th width="50px">批复判断</th>
												<th width="50px">Y19Q1实际纯销</th>
												<th width="60px">目标完成率</th>
												<th width="50px">实际支出</th>
												<th width="220px">备注</th>
												<th width="30px">操作</th>
											</tr>
										</thead>
										<tbody id="distribute-body">
										</tbody>
									</table>
								</form>
								<div class="pageBottom" style="text-align: center;">
									<!-- 分页条-->
									<div id="callBackPager" class="paging_bootstrap pagination"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div id="formList" hidden></div>
			</div>
		</div>
	</div>

	<!-- 页面模板基本js -->
	<script src="${pageContext.request.contextPath}/js/jquery-1.7.1.min.js"></script>
	<script
		src="${pageContext.request.contextPath}/js/jquery.nicescroll.js"
		type="text/javascript"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.min.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/js/jquery.slimscroll.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/fullcalendar.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
	<script
		src="${pageContext.request.contextPath}/js/jquery.easy-pie-chart.js"
		type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/jquery.sparkline.js"
		type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/js/Chart.js"></script>
	<script
		src="${pageContext.request.contextPath}/js/jquery.scrollTo.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/common-scripts.js"></script>

	<!-- layer -->
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
	<!-- 下拉多选，过滤-->
	<script type="text/javascript"
		src="${pageContext.request.contextPath}/js/bootstrap-multiselect.js"></script>
	<link rel="stylesheet"
		href="${pageContext.request.contextPath}/css/bootstrap-multiselect.css"
		type="text/css" />
	<!-- 自动补全 -->
	<script
		src="${pageContext.request.contextPath}/js/bootstrap-typeahead.js"
		type="text/javascript"></script>
	<!-- 分页 -->
	<script src="${pageContext.request.contextPath}/js/extendPagination.js"
		type="text/javascript"></script>
	<!-- 复制 -->
	<script src="${pageContext.request.contextPath}/js/jquery.zclip.min.js"
		type="text/javascript"></script>
		
	<%-- <link href="${pageContext.request.contextPath}/css/bootstrap-select.min.css" rel="stylesheet" />
	<script src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/bootstrap-select.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/defaults-zh_CN.min.js"></script> --%>

<!-- 页面查询条件初始化 -->
<script type="text/javascript">
//查询条件   下拉多选，并过滤 数据源填充 会花点时间，故需要先加载页面，后填充数据
$(document).ready(function () {
    selectMoreItem('province','省份','80px');
    selectMoreItem('city','地市','80px');
    selectMoreItem('county','区县','80px');
    selectMoreItem('product','品种','80px');
    selectMoreItem('page','包装','80px');
    selectMoreItem('isTerminal','重点终端','80px');
    selectMoreItem('isCountry','重点区县','80px');
    selectMoreItem('clientLevel','客户级别','80px');
    selectMoreItem('eventRef','是否批复','80px');
    
    //自动补全 数据源填充
    var client = ${condiMap.client};
    $('#client').typeahead({source: client});
    var terminalQs = ${condiMap.qsterminal};
    $('#terminalQs').typeahead({source: terminalQs});
    
});

//延时加载查询框
function loadQueryDIV(){
	setTimeout($("#query_div").slideDown(),500);
}
</script>

	<!--查询list -->
	<script type="text/javascript">
    function query(pageNumber, pageSize) {
    	if(clicked_count % 2 == 0){
    		$("#query_id").click();
    	}
        var url = "${pageContext.request.contextPath }/task/selectForList.do?pageNumber="
            + pageNumber + "&pageSize=" + pageSize;
        var params = $("#filterForm").serialize();
        queryList(url,params);
    }

    //给table 赋值动态数据
    function createTable(currPage, limit, total, items) {
        var html = [],formHtml=[], showNum = limit;
        if (total - (currPage * limit) < 0) showNum = total - ((currPage - 1) * limit);
        for (var i = 0; i < showNum; i++) {
            html.push('<tr>');
            html.push('<td>' + formatData(items[i].province) + '</td>');
            html.push('<td>' + formatData(items[i].city) + '</td>');
            html.push('<td>' + formatData(items[i].country) + '</td>');
            html.push('<td>' + formatData(items[i].mgr) + '</td>');
            html.push('<td>' + formatData(items[i].client) + '</td>');
            html.push('<td>' + formatData(items[i].clientLevel) + '</td>');
            html.push('<td>' + formatData(items[i].product ) + '</td>');
            html.push('<td>' + formatData(items[i].page) + '</td>');
            html.push('<td>' + formatData(items[i].terminalQs) + '</td>');
            html.push('<td>' + formatData(items[i].terminalType) + '</td>');
            html.push('<td>' + formatData(items[i].terminalLevel) + '</td>'); 
            if(formatData(items[i].isTerminal) === "1"){
                 html.push('<td> <select style="width:45px;" id="isTerminal'+items[i].id+'">');
                 html.push(' <option value="1" selected="true">1</option>');
                 html.push(' <option value="0">0</option>');
                 html.push(' </select></td>');
            } else {
                 html.push('<td> <select style="width:45px;" id="isTerminal'+items[i].id+'">');
                 html.push(' <option value="1">1</option>');
                 html.push(' <option value="0" selected="true">0</option>');
                 html.push(' </select></td>');
            }
            if(formatData(items[i].isCountry) === "1"){
                 html.push('<td> <select style="width:48px;" id="isCountry'+items[i].id+'">');
                 html.push(' <option value="1" selected="true">1</option>');
                 html.push(' <option value="0">0</option>');
                 html.push(' </select></td>');
            } else {
                 html.push('<td> <select style="width:48px;" id="isCountry'+items[i].id+'">');
                 html.push(' <option value="1">1</option>');
                 html.push(' <option value="0" selected="true">0</option>');
                 html.push(' </select></td>');
            }
            
            html.push('<td>' + formatData(items[i].policyPrice) + '</td>');
            html.push('<td>' + formatData(items[i].m1) + '</td>');
            html.push('<td>' + formatData(items[i].m2) + '</td>');
            html.push('<td>' + formatData(items[i].m3) + '</td>');
            
            html.push('<input type="hidden" style="width:38px;" id="m1_'+items[i].id+'" value="' + formatData(items[i].m1) + '"/>');
            html.push('<input type="hidden" style="width:38px;" id="m2_'+items[i].id+'" value="' + formatData(items[i].m2) + '"/>');
            html.push('<input type="hidden" style="width:38px;" id="m3_'+items[i].id+'" value="' + formatData(items[i].m3) + '"/>');
            
            html.push('<td> <input type="text" style="width:38px;" id="taskM1'+items[i].id+'" onchange="fillTarget(this,'+items[i].id+')" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;);" value="' + formatData(items[i].taskM1) + '"/></td>');
            html.push('<td> <input type="text" style="width:38px;" id="taskM2'+items[i].id+'" onchange="fillTarget(this,'+items[i].id+')" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;);" value="' + formatData(items[i].taskM2) + '"/></td>');
            html.push('<td> <input type="text" style="width:38px;" id="taskM3'+items[i].id+'" onchange="fillTarget(this,'+items[i].id+')" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;);" value="' + formatData(items[i].taskM3) + '"/></td>');
            html.push('<td> <label style="color:red;" id="taskGrowthRateText'+items[i].id+'">' + formatData(items[i].taskGrowthRate) + '</label></td>');
            html.push('<input type="hidden" style="width:38px;" id="taskGrowthRate'+items[i].id+'" value="' + formatData(items[i].taskGrowthRate) + '"/>');
            
            html.push('<td> <textarea id="event'+items[i].id+'" rows="2" cols="30">' + formatData(items[i].event) + '</textarea></td>');
            html.push('<td> <input type="text" style="width:38px;" onchange="fill(this)" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;);" id="eventPrice'+items[i].id+'" value="' + formatData(items[i].eventPrice) + '"/></td>');
            
            if(formatData(items[i].eventRef) === "1"){
                html.push('<td> <select style="width:48px;" id="eventRef'+items[i].id+'">');
                html.push(' <option value="1" selected="true">1</option>');
                html.push(' <option value="0">0</option>');
                html.push(' </select></td>');
           } else {
                html.push('<td> <select style="width:48px;" id="eventRef'+items[i].id+'">');
                html.push(' <option value="1">1</option>');
                html.push(' <option value="0" selected="true">0</option>');
                html.push(' </select></td>');
           }
            
           html.push('<td>' + formatData(items[i].quarterActual) + '</td>');
           html.push('<input type="hidden" style="width:38px;" id="quarterActual'+items[i].id+'" value="' + formatData(items[i].quarterActual) + '"/>');
           
           
           html.push('<td> <label style="color:red;" id="completeRateText'+items[i].id+'">' + formatData(items[i].completeRate) + '</label></td>');
           html.push('<input type="hidden" style="width:38px;" id="completeRate'+items[i].id+'" value="' + formatData(items[i].completeRate) + '"/>');
           
           html.push('<td> <input type="text" style="width:38px;" id="actualCost'+items[i].id+'" onchange="fill(this)" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;);" value="' + formatData(items[i].actualCost) + '"/></td>');
           html.push('<td> <textarea id="note'+items[i].id+'" rows="2" cols="30">' + formatData(items[i].note) + '</textarea></td>');
           html.push('<td> <a href="#" onclick="update('+items[i].id+');"><span style="color:red;">保存</span></a></td>');
           html.push('</tr>');
        }
        var mainObj = $('#distribute-body');
        mainObj.empty();
        mainObj.html(html.join(''));
    };
</script>

<script>
function update(id) {
    var isTerminal = $("#isTerminal"+id).val();
    var isCountry = $("#isCountry"+id).val();
    var taskM1 = $("#taskM1"+id).val();
    var taskM2 = $("#taskM2"+id).val();
    var taskM3 = $("#taskM3"+id).val();
    var event = $("#event"+id).val();
    var eventPrice = $("#eventPrice"+id).val();
    var eventRef = $("#eventRef"+id).val();
    var actualCost = $("#actualCost"+id).val();
    var note = $("#note"+id).val();
    var taskGrowthRate = $("#taskGrowthRate"+id).val();
    var completeRate = $("#completeRate"+id).val();
    
    var params = {isTerminal:isTerminal,isCountry:isCountry,taskM1:taskM1,
            taskM2:taskM2,taskM3:taskM3,event:event,
            eventPrice:eventPrice,eventRef:eventRef,actualCost:actualCost,
            note:note,taskGrowthRate:taskGrowthRate,completeRate:completeRate};
    var url = "${pageContext.request.contextPath }/task/saveOrUpdate.do?flag=E&id="+id;
    sendRequest(url, params, function(result) {
        layer.alert(result.msg);
    });
}

function fill(_this) {
	if(_this.value == ""){
        _this.value = 0;
    } else {
    	_this.value = parseInt(_this.value);
    }
}

function fillTarget(_this,id){
    if(_this.value == ""){
        _this.value = 0;
    } else {
    	_this.value = parseInt(_this.value);
    }
    var taskM1 = parseInt($("#taskM1"+id).val());
    var taskM2 = parseInt($("#taskM2"+id).val());
    var taskM3 = parseInt($("#taskM3"+id).val());
    
    var m1 = parseInt($("#m1_"+id).val());
    var m2 = parseInt($("#m2_"+id).val());
    var m3 = parseInt($("#m3_"+id).val());
    
    var Q = parseInt($("#quarterActual"+id).val());
    
    //目标增长率
    var v = parseFloat((taskM1+taskM2+taskM3)/(m1+m2+m3)-1);
    var a = v.toFixed(2);
    var t = (a*100).toFixed(0);
    var tv = t+'%';
    if((m1+m2+m3) == 0){
        tv = 'N/A';
    } 
    $("#taskGrowthRateText"+id).text(tv);
    $("#taskGrowthRate"+id).val(tv);
    
    //目标完成率
    var b = parseFloat(Q/(taskM1+taskM2+taskM3));
    var bb = b.toFixed(2);
    var wcv = (bb*100).toFixed(0)+'%';
    if((taskM1+taskM2+taskM3) == 0){
        wcv = 'N/A';
    }
    $("#completeRateText"+id).text(wcv);
    $("#completeRate"+id).val(wcv);
}

function changeTwoDecimal_f(x) {
	  var f_x = parseFloat(x);
	  if (isNaN(f_x)) {
	    return false;
	  }
	  var f_x = Math.round(x * 100) / 100;
	  var s_x = f_x.toString();
	  var pos_decimal = s_x.indexOf('.');
	  if (pos_decimal < 0) {
	    pos_decimal = s_x.length;
	    s_x += '.';
	  }
	  while (s_x.length <= pos_decimal + 2) {
	    s_x += '0';
	  }
	  return s_x;
	}
</script>
<!-- 新增、更新 -->
<script type="text/javascript">
    var htmls = $("#form_div").html();
    var ret = null;
    var open = false;
    function showOpen(id,type) {
        $("#form_div").remove();
        layer.open({
            title: [type+'<span style="color:red;font-size:12px;margin-left:10px;">*表示该项必填</span>', 'font-size:18px;'],
            type:1,
            content: htmls, //这里content是一个普通的String
            btn: ['确认', '取消'],
            yes: function(index, layero){
                var ret = checkNull("submitForm");
                if (ret == "false") {
                    open = true;
                    return open;
                }
                //一点击确认就关闭对话框
                layer.closeAll();
                //加载等待框
                layer.load(2);
                var action ="";
                if("新增"==type){
                    action = "${pageContext.request.contextPath }/basis/saveOrUpdate.do?flag=N";
                }else if("修改"==type){
                    action = "${pageContext.request.contextPath }/basis/saveOrUpdate.do?flag=E";
                }
                var params = $("#submitForm").serialize();
                sendRequest(action, params, function(result) {
                    var code = result.code;
                    if (code == -2) { //excel校验不通过
                        open = true;
                        errorInfo(result.msg);
                    } else if (code == -1) { // 有错误
                        layer.alert(result.msg);
                    } else if (code > 0) {
                        //查询方法里有关闭load(2)的方法
                        query(pNumber, pSize);
                        layer.alert(result.msg);
                    }
                });
                return open;
            }
            ,cancel: function(){
                layer.closeAll();
            }
            ,area: ['800px', '500px']
        });
        
        //修改时，异步回显数据
        if("修改"==type){
            var url = "${pageContext.request.contextPath }/basis/selectByID.do";
            sendRequest(url,{"id" : id},function(result) {
                var code = result.code;
                var ret = result.msg;
                if (code > 0) {
                    $("#idU").val(ret.id);
                    $("#mgrU").val(ret.mgr);
                    $("#daquU").val(ret.daqu);
                    $("#provinceU").val(ret.province);
                    $("#cityU").val(ret.city);
                    $("#countyU").val(ret.country);
                    $("#spaceU").val(ret.space);
                    $("#productU").val(ret.product);
                    //新增、更新界面的下拉多选过滤 
                    $("#daquU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择大区', enableFiltering: true, maxHeight: 300, buttonWidth: '166px'});
                    $("#spaceU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择片区',enableFiltering: true, maxHeight: 300,buttonWidth: '125px'});
                    $("#provinceU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择省份',enableFiltering: true,maxHeight: 300,buttonWidth: '125px'});
                    $("#productU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择分组标识',maxHeight: 300,buttonWidth: '150px'});
                }
            });
        } else {
            //新增、更新界面的下拉多选过滤 
            var url = "${pageContext.request.contextPath }/register/nothing.do";
            sendRequest(url,null,function(result) {
                var code = result.code;
                var ret = result.msg;
                if (code > 0) {
                     //新增、更新界面的下拉多选过滤 
                     $("#daquU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择大区', enableFiltering: true, maxHeight: 300, buttonWidth: '166px'});
                     $("#spaceU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择片区',enableFiltering: true, maxHeight: 300,buttonWidth: '125px'});
                     $("#provinceU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择省份',enableFiltering: true,maxHeight: 300,buttonWidth: '125px'});
                     $("#productU").multiselect({includeSelectAllOption:true,nonSelectedText: '请选择分组标识',maxHeight: 300,buttonWidth: '150px'});
                }
            });
        }
        
        //新增、更新界面的自动补全 数据填充
        var mgr = ${condiMap.mgr};
        $("#mgrU").typeahead({source: mgr});
        var city = ${condiMap.cityStr};
        $("#cityU").typeahead({source: city});
        var county = ${condiMap.countryList};
        $("#countyU").typeahead({source: county});
    }
</script>

<script type="text/javascript">
function deleteById(){
    var deleteHtml = $("#deleteDiv").html();
    $("#deleteDiv").remove();
    layer.open({
            title: ['删除基础库数据', 'font-size:18px;'],
            type:1,
            content: deleteHtml, // 这里content是一个普通的String
            btn: ['删除', '取消'],
            yes: function(index, layero){
                var ids = $("#idD").val();
                if(ids.trim().length<=0){
                    layer.alert("ID不能为空！！！");
                    return;
                }
                layer.confirm('确认要删除['+ids+']吗？', {
                    btn : [ '确认', '取消' ] //按钮
                }, function(index) {
                    layer.close(index);
                    var url = "${pageContext.request.contextPath }/basis/delByIds.do"
                    sendRequest(url, {id:ids},function(result) {
                        var code = result.code;
                        if (code == -1) { // 有错误
                            layer.alert(result.msg);
                        } else if (code > 0) {
                            layer.closeAll();
                            layer.alert(result.msg);
                            query(pNumber,pSize);
                        }
                    });
                }); 
                
            }
            ,btn2: function(index, layero){
                layer.closeAll('loading');
            }
            ,cancel: function(){
                layer.closeAll('loading');
            }
            ,area: ['700px', '180px']
        });

    $("#error-info").removeAttr("hidden");  
}
var trHTML ='<tr id="newTr">'+
+'<td>什么鬼 </td>'
+'<td><input type="text" style="width:38px;" id="provinceA" name="province" class="hideinput noNull" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="cityA" name="city" class="hideinput noNull" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="countryA" name="country" class="hideinput noNull" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="mgrA" name="mgr" class="hideinput noNull" readonly/></td>'
+'<td><input type="text" style="width:35px;" id="clientA" name="client" onchange="selectInfoBy();" value=""/></td>'
+'<td><input type="text" style="width:38px;" id="clientLevelA" name="clientLevel" class="hideinput" readonly/></td>'
+'<td><select id="productA" name="product" style="width:38px;padding:0px 0px;" onchange="selectInfoBy();">'
+'<c:forEach items="${products}" var="product" >'
+'<option value="${product}">${product}</option>'
+'</c:forEach>'
+'</select></td>'
+'<td><select id="pageA" name="page" style="width:38px;padding:0px 0px;" onchange="selectInfoBy();">'
+'<c:forEach items="${packs}" var="page">'
+'<option value="${page}">${page}</option>'
+'</c:forEach>'
+'</select></td>'
+'<td><input type="text" style="width:60px;" id="terminalQsA" name="terminalQs" class="noNull" onchange="selectInfoBy(this)" value=""/></td>'
+'<td><input type="text" style="width:38px;" id="terminalTypeA" name="terminalType" class="hideinput noNull" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="terminalLevelA" name="terminalLevel" class="hideinput noNull" readonly/></td>' 
+'<td> <select style="width:45px;" id="isTerminalA" name="isTerminal">'
+'<option value="0">0</option>'
+'<option value="1">1</option>'
+'</select></td>'
+'<td> <select style="width:48px;" id="isCountryA" name="isCountry">'
+'<option value="0">0</option>'
+'<option value="1">1</option>'
+'</select></td>'
+'<td><input type="text" style="width:38px;" id="policyPriceA" name="policyPrice" class="hideinput noNull" value="0" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="m1A" name="m1" class="hideinput noNull" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="m2A" name="m2" class="hideinput noNull" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="m3A" name="m3" class="hideinput noNull" readonly/></td>'
+'<td> <input type="text" style="width:38px;" id="taskM1A" name="taskM1" class="noNull" onchange="fill(this);" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;" value="0"/></td>'
+'<td> <input type="text" style="width:38px;" id="taskM2A" name="taskM2" class="noNull" onchange="fill(this);" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;" value="0"/></td>'
+'<td> <input type="text" style="width:38px;" id="taskM3A" name="taskM3" class="noNull" onchange="fill(this);" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;" value="0"/></td>'
+'<td><input type="text" style="width:38px;" id="taskGrowthRateA" name="taskGrowthRate" class="hideinput noNull" value="0" readonly/></td>'
+'<td> <textarea id="eventA" rows="2" cols="30" name="event"></textarea></td>'
+'<td> <input type="text" style="width:38px;" class="noNull" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;" id="eventPriceA" name="eventPrice" value="0"/></td>'
+'<td> <select style="width:48px;" id="eventRefA" name="eventRef">'
+'<option value="1" >1</option>'
+'<option value="0" selected="true">0</option>'
+'</select></td>'
+'<td><input type="text" style="width:38px;" id="quarterActualA" name="quarterActual" class="hideinput noNull" value="0" readonly/></td>'
+'<td><input type="text" style="width:38px;" id="completeRateA" name="completeRate" class="hideinput noNull" value="0" readonly/></td>'
+'<td><input type="text" style="width:38px;" name="actualCost" class="noNull" id="actualCostA" onkeyup="this.value=this.value.replace(/[^0-9]/g, &#39;&#39;" value="0"/></td>'
+'<td><textarea id="noteA" rows="2" cols="30" name="note"></textarea></td>'
+'<td><a href="#" onclick="save(this);"><span style="color:red;">保存</span></a></td>'
+'</tr>';

function addRow(){
	$("#newadd").hide();
    $("#distribute-thead").after(trHTML);
}

function selectInfoBy(){
	
        
    var client = $("#clientA").val();
    var product = $("#productA").val();
    var page = $("#pageA").val();
    var terminalQs = $("#terminalQsA").val();
    if(client!=""&&product!=""&&page!=""&&terminalQs!=""){
    	layer.msg('系统正在联想其他未填写项，请稍候……', {icon: 16}, function(){
            layer.closeAll();
            layer.load(2);
	        var url = "${pageContext.request.contextPath }/task/selectInfoBy.do";
	        var params = {client:client,product:product,page:page,terminalQs:terminalQs};
	        sendRequest(url, params, function(result) {
	            var code = result.code;
	            var msg = result.msg;
	            if (code == -1) { // 有错误
	            	$("#clientA").val("");
	                $("#productA").val("");
	                $("#pageA").val("");
	                $("#terminalQsA").val("");
	                layer.alert(result.msg);
	            } else if (code > 0) {
	            	if(msg!=null){
	            		//获取联想到的数据填充到td中
	            		$("#provinceA").val(msg.province);
	            		$("#cityA").val(msg.city);
	            		$("#mgrA").val(msg.mgr);
	            		$("#countryA").val(msg.country);
	            		$("#clientLevelA").val(msg.clientLevel);
	            		
	            		$("#terminalTypeA").val(msg.terminalType);
	                    $("#terminalLevelA").val(msg.terminalLevel);
	                    $("#policyPriceA").val(msg.policyPrice);
	                    $("#m1A").val(msg.m1);
	                    $("#m2A").val(msg.m2);
	                    
	                    $("#m3A").val(msg.m3);
	                    $("#quarterActualA").val(msg.quarterActual);
	            	}else{
	            		alert("没有匹配！");
	            	}
	            }
	        });
	        layer.closeAll();
        });
    }
    
}

function save(){
	var ret = checkNull('newTask');
    if(ret=="true"){
		var data = $("#newTask").serialize();
		var url = $("#newTask").attr("action");
		sendRequest(url, data, function(result) {
	        var code = result.code;
	        if (code == -1) { // 有错误
	            layer.alert(result.msg);
	        } else if (code > 0) {
	            layer.closeAll();
	            layer.alert(result.msg);
	            $("#newTr").remove();
	            $("#newadd").show();
	            query(pNumber,pSize);
	        }
	    })
    }
    
}
function fill(_this){
	if(_this.value == ""){
        _this.value = 0;
    } else {
        _this.value = parseInt(_this.value);
    }
    var taskM1 = parseInt($("#taskM1A").val());
    var taskM2 = parseInt($("#taskM2A").val());
    var taskM3 = parseInt($("#taskM3A").val());
    
    var m1 = parseInt($("#m1A").val());
    var m2 = parseInt($("#m2A").val());
    var m3 = parseInt($("#m3A").val());
    
    var Q = parseInt($("#quarterActualA").val());
    //目标增长率
    var tv = ((taskM1+taskM2+taskM3)/(m1+m2+m3)-1).toFixed(2)*100+'%';
    if((m1+m2+m3) == 0){
        tv = 'N/A';
    } 
    $("#taskGrowthRateA").val(tv);
    
    //目标完成率
    var wcv = (Q/(taskM1+taskM2+taskM3)).toFixed(2)*100+'%';
    if((taskM1+taskM2+taskM3) == 0){
        wcv = 'N/A';
    }
    $("#completeRateA").val(wcv);
}
</script>
<style type="text/css">
#newTask .hideinput{  
    background:none;  
    outline:none;  
    border:0px;
}
</style>
<script src="${pageContext.request.contextPath}/javascript/httpService.js"></script>
</body>
</html>